package socilgirl.dell.mydemo.httpmanager.imhttpinterface;

import android.text.TextUtils;


import java.util.Arrays;
import java.util.List;

import socilgirl.dell.mydemo.httpmanager.DownData;
import socilgirl.dell.mydemo.httpmanager.HttpManagerConstant;
import socilgirl.dell.mydemo.httpmanager.httpinterface.IDataParameter;

/**
 * Created by ${小强} on 2017/10/30.
 */

public class DataParameters implements IDataParameter {
    private Builder mBuilder;

    private DataParameters(Builder builder) {
        mBuilder = builder;
    }

    @Override
    public String getUrl() {
        return mBuilder.mUrl;
    }

    @Override
    public int getMethod() {
        return mBuilder.mMethod;
    }

    @Override
    public DownData.DownFile getFile() {
        return mBuilder.mDownData.getDownFiles().get(0);
    }

    @Override
    public DownData getFiles() {
        return mBuilder.mDownData;
    }

    @Override
    public DownData getFileKeys() {
        return mBuilder.mDownData;
    }

    @Override
    public DownData getInputStream() {
        return mBuilder.mDownData;
    }

    @Override
    public DownData getBytes() {
        return mBuilder.mDownData;
    }


    public static Builder newBuilder() {
        return new Builder();
    }

    public static class Builder {
        private String mUrl;
        private int mMethod;
        private DownData mDownData;


        public Builder setUrl(String url) {
            if (TextUtils.isEmpty(url)) {
                throw new NullPointerException(HttpManagerConstant.URL_NULL);
            }
            this.mUrl = url;
            return this;
        }

        public Builder setMethod(int method) {
            this.mMethod = method;
            return this;
        }

        public Builder setFile(DownData.DownFile downFile) {
            if (downFile == null) {
                throw new NullPointerException(HttpManagerConstant.FILE_NULL);
            }

            DownData downData = new DownData();
            downData.setDownFiles(Arrays.asList(downFile));
            this.mDownData = downData;
            this.mMethod = HttpManagerConstant.ONE_FILE;
            return this;
        }

        public Builder setFileKeys(List<DownData.DownFile> downFile) {
            if (downFile == null) {
                throw new NullPointerException(HttpManagerConstant.FILE_NULL);
            }
            DownData downData = new DownData();
            downData.setDownFiles(downFile);
            this.mDownData = downData;
            this.mMethod = HttpManagerConstant.MORE_FILE;
            return this;
        }

        public Builder setFileLists(DownData downData) {
            if (downData == null) {
                throw new NullPointerException(HttpManagerConstant.FILE_NULL);
            }
            this.mDownData = downData;
            this.mMethod = HttpManagerConstant.MORE_FILE_KEYS;
            return this;
        }

        public Builder setInputStreams(DownData downData) {
            if (downData == null) {
                throw new NullPointerException(HttpManagerConstant.FILE_NULL);
            }
            this.mDownData = downData;
            this.mMethod = HttpManagerConstant.FILE_INPUTSTREAM;
            return this;
        }

        public Builder setBytes(DownData downData) {
            if (downData == null) {
                throw new NullPointerException(HttpManagerConstant.FILE_NULL);
            }
            this.mDownData = downData;
            this.mMethod = HttpManagerConstant.FILE_IBYTE;
            return this;
        }

        public DataParameters build() {
            return new DataParameters(this);

        }
    }
}
